﻿
////////////////////////////////////////////////////////////////////////////////////////////
// 文件名: SysViewGroupBLL.gen.cs
//
// 模块名称: SysViewGroup
//
// 作者: yqf
//
// 历史记录（记录修改记录，修改文件后请添加修改记录，注明修改时间、修改人，修改内容）:
// 2013-01-22    yqf    创建文件
////////////////////////////////////////////////////////////////////////////////////////////

using System;
using System.Data;
using System.Data.Common;
using System.Text;
using Model;
using DAL;
using Common;
using System.Collections.Generic;
using System.Data.SqlClient;

namespace BLL
{
    /// <summary>
    /// SysViewGroup表业务逻辑层
    /// </summary>
    public partial class SysViewGroupBLL
    {
        public SysViewGroupBLL(LoginInfo info)
        {
            loginInfo = info;
        }
        public LoginInfo loginInfo
        {
            get;
            set;
        }
        /// <summary>
        /// 更新SysViewGroup表记录
        /// </summary>
        /// <param name="SysViewGroup">SysViewGroup实体对象</param>
        public string Update(IDataParameter[] sqlparams)
        {
            try
            {
                SysViewGroupDAL dal = new SysViewGroupDAL(loginInfo);
                new SysOperationLog(loginInfo).Log("视图组管理", loginInfo.UserIP, OperationAction.更新, OperationStatus.成功, "更新视图组信息,操作成功", loginInfo.UserName);
                return dal.Update(sqlparams);
            }
            catch (Exception ex)
            {
                new SysOperationLog(loginInfo).Log("视图组管理", loginInfo.UserIP, OperationAction.更新, OperationStatus.失败, "更新视图组信息,操作失败：" + ex.Message, loginInfo.UserName);
                return "0";
            }
        }
        /// <summary>
        /// 更新UpdateApprove表记录
        /// </summary>
        /// <param name="SysViewGroup">UpdateApprove实体对象</param>
        public void UpdateApprove(IDataParameter[] sqlparams)
        {
            try
            {
                SysViewGroupDAL dal = new SysViewGroupDAL(loginInfo);
                dal.UpdateApprove(sqlparams);
                new SysOperationLog(loginInfo).Log("视图组管理", loginInfo.UserIP, OperationAction.更新, OperationStatus.成功, "更新视图审核信息,操作成功", loginInfo.UserName);
            }
            catch (Exception ex)
            {
                new SysOperationLog(loginInfo).Log("视图组管理", loginInfo.UserIP, OperationAction.更新, OperationStatus.失败, "更新视图审核信息,操作失败：" + ex.Message, loginInfo.UserName);
            }
        }
        public void CheckApprove(Dictionary<string, object> appInfo)
        {
            try
            {
                SysViewGroupDAL dal = new SysViewGroupDAL(loginInfo);
                dal.CheckApprove(appInfo);
                new SysOperationLog(loginInfo).Log("视图组管理", loginInfo.UserIP, OperationAction.更新, OperationStatus.成功, "视图审核操作,操作成功", loginInfo.UserName);
            }
            catch (Exception ex)
            {
                new SysOperationLog(loginInfo).Log("视图组管理", loginInfo.UserIP, OperationAction.更新, OperationStatus.失败, "视图审核操作,操作失败：" + ex.Message, loginInfo.UserName);
            }
        }
        /// <summary>
        /// 根据ID字段获取SysViewGroup实体对象
        /// </summary>
        /// <param name="id">ID</param>
        public SysViewGroup GetItem(string id)
        {
            try
            {
                SysViewGroupDAL dal = new SysViewGroupDAL(loginInfo);
                return dal.GetItem(id);
            }
            catch (Exception ex)
            {
                Logger.LogError("SysViewGroupBLL", "GetItem", AppError.EROR, 0, ex, "取SysViewGroup信息出错。",
                                String.Format("id = {0}", id));
                return new SysViewGroup();
            }
        }
        /// <summary>
        /// 根据ID字段删除SysViewGroup实体对象
        /// </summary>
        /// <param name="id">ID</param>
        public string Delete(string id)
        {
            try
            {
                SysViewGroupDAL dal = new SysViewGroupDAL(loginInfo);
                new SysOperationLog(loginInfo).Log("视图组管理", loginInfo.UserIP, OperationAction.删除, OperationStatus.成功, "删除视图组操作,操作成功", loginInfo.UserName);
                return dal.Delete(id);
            }
            catch (Exception ex)
            {
                new SysOperationLog(loginInfo).Log("视图组管理", loginInfo.UserIP, OperationAction.删除, OperationStatus.失败, "删除视图组操作,操作失败：" + ex.Message, loginInfo.UserName);
                return "0";
            }
        }
        public bool DeleteCallBack(string id)
        {
            SysViewGroupDAL dal = new SysViewGroupDAL(loginInfo);
            //new SysOperationLog(loginInfo).Log("视图组管理", loginInfo.UserIP, OperationAction.删除, OperationStatus.成功, "删除视图组操作,操作成功", loginInfo.UserName);
            return dal.DeleteCallBack(id);
        }
        //删除视图与组关联
        public void Delete(string id, string gid)
        {
            try
            {
                SysViewGroupDAL dal = new SysViewGroupDAL(loginInfo);
                dal.Delete(id, gid);
                new SysOperationLog(loginInfo).Log("视图组管理", loginInfo.UserIP, OperationAction.删除, OperationStatus.成功, "删除视图与视图组关联操作,操作成功", loginInfo.UserName);
            }
            catch (Exception ex)
            {
                new SysOperationLog(loginInfo).Log("视图组管理", loginInfo.UserIP, OperationAction.删除, OperationStatus.失败, "删除视图与视图组关联操作,操作失败：" + ex.Message, loginInfo.UserName);
            }
        }

        public DataTable ViewTableInfo(string schema, string name)
        {
            try
            {
                SysViewGroupDAL dal = new SysViewGroupDAL(loginInfo);
                return dal.ViewTableInfo(schema, name);
            }
            catch (Exception ex)
            {
                Logger.LogError("SysViewGroupBLL", "ViewTableInfo", AppError.EROR, 0, ex, "ViewTableInfo信息出错。", "");
                return new DataTable();
            }
        }
        /// <summary>
        /// 获取SysViewGroup实体数量
        /// </summary>
        /// <param name="id">ID</param>
        public int GetListCount(IDataParameter[] sqlparams)
        {
            try
            {
                SysViewGroupDAL dal = new SysViewGroupDAL(loginInfo);
                return dal.GetListCount(sqlparams);
            }
            catch (Exception ex)
            {
                Logger.LogError("SysViewGroupBLL", "GetListCount", AppError.EROR, 0, ex, "获取SysViewGroup实体数量出错。", "");
                return 0;
            }
        }
        /// <summary>
        /// 根据ID字段获取SysViewGroup实体对象列表
        /// </summary>
        /// SqlParameter[] sqlparams</param>
        /// <returns>SysViewGroup实体对象列表</returns>
        public List<SysViewGroup> GetInfoList(IDataParameter[] sqlparams)
        {
            try
            {
                SysView_OnInit();
                SysViewGroupDAL dal = new SysViewGroupDAL(loginInfo);
                return dal.GetInfoList(sqlparams);
            }
            catch (Exception ex)
            {
                Logger.LogError("SysViewGroupBLL", "GetInfoList", AppError.EROR, 0, ex, "获取SysViewGroup信息出错。", "");
                return new List<SysViewGroup>();
            }
        }
        /// <summary>
        /// 初始化视图列表
        /// </summary>
        public void SysView_OnInit()
        {
            try
            {
                SysTBViewDAL dal = new SysTBViewDAL(loginInfo);
                dal.SysView_OnInit();
                //SysOperationLog.Log("", loginInfo.UserIP, OperationAction.更新, OperationStatus.成功, "更新对接系统视图操作,操作成功", loginInfo.UserName);
            }
            catch (Exception ex)
            {
                new SysOperationLog(loginInfo).Log("", loginInfo.UserIP, OperationAction.更新, OperationStatus.失败, "更新对接系统视图操作,操作失败：" + ex.Message, loginInfo.UserName);
            }
        }

        #region SysViewGroup

        public SysViewGroup GetViewGroupByGroupID(string groupID)
        {
            SysViewGroupDAL dal = new SysViewGroupDAL(loginInfo);
            return dal.GetViewGroupByGroupID(groupID);
        }

        public List<SysViewGroup> GetViewGroupBySysCode(string sysCode
    , string orderBy, bool asc
    , int pageIndex, int pageSize, out int recordCount)
        {
            SysViewGroupDAL dal = new SysViewGroupDAL(loginInfo);
            return dal.GetViewGroupBySysCode(sysCode, orderBy, asc
                , pageIndex, pageSize, out  recordCount);
        }

        public List<SysViewGroup> GetViewGroupBySysID(string sysID, string groupName
    , string orderBy, bool asc
    , int pageIndex, int pageSize, out int recordCount)
        {
            SysViewGroupDAL dal = new SysViewGroupDAL(loginInfo);
            return dal.GetViewGroupBySysID(sysID, groupName, orderBy, asc
                , pageIndex, pageSize, out  recordCount);
        }

        public List<SysViewGroup> GetViewGroupBySysID(string sysID, string groupName)
        {
            SysViewGroupDAL dal = new SysViewGroupDAL(loginInfo);
            return dal.GetViewGroupBySysID(sysID, groupName);
        }
        public List<SysViewGroup> GetViewGroupBySysIDWithOutGUID(string sysID, string groupID, string groupName)
        {
            SysViewGroupDAL dal = new SysViewGroupDAL(loginInfo);
            return dal.GetViewGroupBySysIDWithOutGUID(sysID, groupID, groupName);
        }

        public List<SysViewGroup> GetViewGroupByGroupName(string groupName, string SysName)
        {
            SysViewGroupDAL dal = new SysViewGroupDAL(loginInfo);
            return dal.GetViewGroupByGroupName(groupName, SysName);
        }

        public int Insert(SysViewGroup groupInfo)
        {
            SysViewGroupDAL dal = new SysViewGroupDAL(loginInfo);
            return dal.Insert(groupInfo);
        }

        public int Update(SysViewGroup groupInfo)
        {
            SysViewGroupDAL dal = new SysViewGroupDAL(loginInfo);
            return dal.Update(groupInfo);
        }

        public int Delete2(string groupID)
        {
            SysViewGroupDAL dal = new SysViewGroupDAL(loginInfo);
            return dal.Delete2(groupID);
        }
        #endregion

        #region ETL_Push_ViewGroup

        public List<ETL_Push_ViewGroup> GetModelPushConfigByGroupID(string groupID)
        {
            SysViewGroupDAL dal = new SysViewGroupDAL(loginInfo);
            return dal.GetModelPushConfigByGroupID(groupID);
        }

        public int UpdateModelPushConfigs(string groupID, List<ETL_Push_ViewGroup> pushConfigList)
        {
            SysViewGroupDAL dal = new SysViewGroupDAL(loginInfo);
            dal.DeleteModelPushConfigByGroupID(groupID);
            foreach (var pushConfigItem in pushConfigList)
            {
                dal.InsertModelPushConfig(pushConfigItem);
            }
            return 1;
        }

        #endregion

    }
}